package com.team_project.boot.controller;

import com.team_project.boot.entity.Manager;
import com.team_project.boot.mapper.ManagerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@RestController
public class ManagerController {
    @Autowired(required = false)
    ManagerMapper mapper;
    @RequestMapping("/loginManager")
    public int loginM(Manager manager, HttpSession session,String rem, HttpServletResponse response){
        System.out.println("manager = " + manager + ", session = " + session + ", rem = " + rem + ", response = " + response);
        Manager m = mapper.select(manager.getUsername1());
        if (m!=null){
            if (m.getPassword1().equals(manager.getPassword1())){
                session.setAttribute("userM", m);
                if (rem!=null){
                    Cookie cookie = new Cookie("username1", manager.getUsername1());
                    Cookie cookie1 = new Cookie("password1", manager.getPassword1());
                    response.addCookie(cookie);
                    response.addCookie(cookie1);
                }
                return 1;
            }
        }
        return 2;//账号不存在
    }
}
